﻿using System;
using System.Collections.Specialized;
class Program
{
    static void Main(string[] args)
    {
        int max=0, min=10, sum = 0;
        GenericList<int> list = new GenericList<int>();
        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.Add(4);
        list.Add(5);

        //max
        list.ForEach(x => { if (x > max) max = x; });
        Console.WriteLine("max = {0}", max);

        //min
        list.ForEach(x => { if (x < min) min = x; });
        Console.WriteLine("min = {0}", min);

        //sum
        list.ForEach(x =>  sum+= x );
        Console.WriteLine("sum = {0}", sum);
    }
}

public class Node<T>
{
    public Node<T> Next { get; set; }
    public T Data { get; set; }
    public Node(T t)
    {
        Next = null;
        Data = t;
    }
}

public class GenericList<T>
{
    private Node<T> head;
    private Node<T> tail;

    public GenericList()
    {
        tail = head = null;
    }
    public Node<T> Head
    {
        get => head;
    }

    public void Add(T t)
    {
        Node<T> n = new Node<T>(t);
        if(tail==null)
        {
            head = tail = n;
        }
        else
        {
            tail.Next = n;
            tail = n;
        }
    }

    public void ForEach(Action<T>fun)
    {
        Node<T> tmp = Head;
        while(tmp!=null)
        {
            fun(tmp.Data);
            tmp = tmp.Next;
        }
    }
}